package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo.dto.dictionary.DictionaryDto;
import com.example.demo.entity.Dictionary;
import com.example.demo.mapper.DictionaryMapper;
import com.example.demo.service.IDictionaryService;
import com.example.demo.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
public class DictionaryServiceImpl implements IDictionaryService {

    @Autowired
    DictionaryMapper dictionaryMapper;

    @Override
    public Optional<List<Dictionary>> selectListByParentId(Integer parentId) {
        LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper();
        wrapper.eq(Dictionary::getParentId, parentId);
        Optional<List<Dictionary>> dictionaryList = Optional.ofNullable(dictionaryMapper.selectList(wrapper));
        return dictionaryList;
    }

    @Override
    public Optional<Dictionary> selectOneByKey(Integer key) {
        LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper<>();
        wrapper
                .eq(Dictionary::getStatus, 1)
                .eq(Dictionary::getId, key);
        Optional<Dictionary> dictionary = Optional.ofNullable(dictionaryMapper.selectOne(wrapper));
        return dictionary;
    }
}
